package com.zy.explore.strategy.infrastructure.strategy;

import com.zy.explore.strategy.infrastructure.enums.VipTypeEnum;
import com.zy.explore.strategy.interfaces.vo.VipRealCostVO;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * description 普通会员计算规则
 *
 * @author 🇨🇳中国印🇨🇳
 * @date 2021年07月03日 02:21
 */
public class NormalVipCalcStrategy implements CalcStrategy {

    /**
     * 计算普通VIP最终消费
     *
     * 当用户消费满1000 金额 普通会员 打98折
     *
     * @param money 花费金钱
     * @return {@link VipRealCostVO}
     */
    @Override
    public VipRealCostVO calc(BigDecimal money) {
        String zero = "0";
        String oneThousand = "1000";
        if (money.compareTo(new BigDecimal(zero)) == 0 || money.compareTo(new BigDecimal(oneThousand)) < 1) {
            return VipRealCostVO.builder().vipType(VipTypeEnum.NORMAL_VIP.getVipType()).realCosts(money.toString()).build();
        }
        DecimalFormat df = new DecimalFormat("#.##");
        return VipRealCostVO.builder().vipType(VipTypeEnum.NORMAL_VIP.getVipType()).realCosts(df.format(money.multiply(new BigDecimal("0.98")))).build();
    }

    @Override
    public String getType() {
        return VipTypeEnum.NORMAL_VIP.getVipType();
    }
}
